from LeetCoder import *


class Solution:

    def smallestString(self, s: str) -> str:

        def f(a):
            if a == 'a':
                return 'z'
            return chr(ord(a) - 1)

        ans = []
        i = 0
        while i < len(s) and s[i] == 'a':
            ans.append(s[i])
            i += 1
        cnt = 0
        while i < len(s) and s[i] != 'a':
            cnt += 1
            ans.append(f(s[i]))
            i += 1
        while i < len(s):
            ans.append(s[i])
            i += 1
        if cnt == 0:
            ans[-1] = f(ans[-1])
        return "".join(ans)


def f(a):
    return chr(ord(a) - 1)


print(f('b'))
